#include <iostream>
using namespace std;

/*
1、Create a class Counted that contains an int id and a static int count. The default constructor should begin:
Counted( ) : id(count++) {. It should also print its id and that it’s being created. The destructor should print that it’s being destroyed and its id. Test your class.

2、Prove to yourself that new and delete always call the constructors and destructors by creating an object of class Counted (from Exercise 1) with new and destroying it with delete. Also create and destroy an array of these objects on the heap.
*/

class Counted{
public:
	int id;
	static int count;
	
	Counted():id(count++){
		cout << "the object of Counted is being created and the id = " << id << endl;
	}
	
	~Counted(){
		cout << "the object of Counted is being destroyed and the id = " << id << endl;
	}
};

int Counted::count = 1;

int main(int argc, char *argv[]) 
{
	//create and destroy an object
	Counted *c1 = new Counted();
	delete c1;
	
	//create and destroy an array
	Counted *arr = new Counted[5];
	delete[] arr;
}